<template>
	<xn-form-container
		:title="'查看授权申请'"
		:width="700"
		v-model:open="open"
		:destroy-on-close="true"
		@close="onClose"
	>
		<license-detail v-model:form-data="formData" />
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="licenseApplicationForm">
	import tool from '@/utils/tool'
	import { cloneDeep } from 'lodash-es'
	import bizGroupApi from '@/api/biz/bizGroupApi'
	import customerInfoApi from '@/api/biz/customerInfoApi'
	import softwareVersionApi from '@/api/biz/softwareVersionApi'
	import LicenseDetail from '@/views/biz/licenseapplication/LicenseDetail.vue'
	import productModuleApi from "@/api/biz/productModuleApi";
	// 抽屉状态
	const open = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)
	const buildStateOptions = ref([])
	const approvalStatusOptions = ref([])
	const stateOptions = ref([])
	const typeOptions = ref([])
	const versionOptions = ref([])
	const applicants = ref([])
	const customs = ref([])
	// 打开抽屉
	const onOpen = (record) => {
		open.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)

			if (formData.value.version){
				softwareVersionApi.softwareVersionDetail({ id: formData.value.version }).then((res) => {
					let builderType = res.builderType
					let param = {
						builder: builderType
					}
					productModuleApi.productModuleList(param).then((res) => {
						let moduleOptionArray = res
						let moduleName = ''
						if (formData.value.module) {
							let moduleArray = formData.value.module.split(',')
							moduleOptionArray.forEach(item => {
								let code = item.code
								if (code) {
									if (moduleArray.indexOf(code) !== -1) {
										moduleName += item.name + " "
									}
								}
							})
							formData.value.moduleName = moduleName
						}
					})
				})
			}
		}
		buildStateOptions.value = tool.dictList('BUILD_STATE')
		approvalStatusOptions.value = tool.dictList('APPROVAL_STATUS')
		stateOptions.value = tool.dictList('LICENSE_STATUS')
		typeOptions.value = tool.dictList('LICENSE_TYPE')
		bizGroupApi.bizGroupOwnUserEntity({ id: '1930923922069581826' }).then((res) => {
			applicants.value = res
		})
		customerInfoApi.customerInfoList().then((res) => {
			customs.value = res
		})
		softwareVersionApi.softwareVersionList().then((res) => {
			versionOptions.value = res
		})

	}
	// 关闭抽屉
	const onClose = () => {
		open.value = false
	}
	// 默认要校验的
	const formRules = {}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
